#include "seg.h"

//字符数组翻译为段码数组
void seg_tran(uchar *seg_str, uchar *seg_buf) {
	uchar i,j=0,temp;
	
	for(i=0; i<8; i++,j++) {
		//匹配字符对应的段码
		switch(seg_str[j]) {
			case '0': temp = 0xC0; break;
			case '1': temp = 0xF9; break;
			case '2': temp = 0xA4; break;
			case '3': temp = 0xB0; break;
			case '4': temp = 0x99; break;
			case '5': temp = 0x92; break;
			case '6': temp = 0x82; break;
			case '7': temp = 0xF8; break;
			case '8': temp = 0x80; break;
			case '9': temp = 0x90; break;
			
			case 'A': temp = 0x88; break;
			case 'B': temp = 0x83; break;
			case 'C': temp = 0xC6; break;
			case 'D': temp = 0xA1; break;
			case 'E': temp = 0x86; break;
			case 'F': temp = 0x8E; break;
			
			case 'P': temp = 0x8C; break; //1000 1100
			case 'H': temp = 0x89; break; //1000 1001
			case 'L': temp = 0xC7; break; //1100 0111
			case 'O': temp = 0xC0; break; //1100 0000
			
			case '-': temp = 0xBF; break;
			case ' ': temp = 0xFF; break;
			default: temp = 0xFF;
		}
		if(seg_str[j+1] == '.') {
			temp &= 0x7F;  //添加小数点
			j++;
		}
		seg_buf[i] = temp; //存储段码
	}
	
}

//数码管显示
void seg_disp(uchar pos, uchar *seg_buf) {
	SEG(0xFF);
	COM(0x01<<pos);
	SEG(seg_buf[pos]);
}


